package htmodels

import (
	"github.com/astaxie/beego/orm"
	"choujiang/models"
)
func HTWxMessageAdd(wxmessage *models.WxMessage) error {
	o := orm.NewOrm()
	_, err := o.Insert(wxmessage)
	return err
}

func HTWxMessageGetDetail(wxmessage *models.WxMessage) error {
	o := orm.NewOrm()
	return o.Read(wxmessage)
}

func HTWxMessageGetCount(search string, searchFiled string , MessageType int) (int64, error) {
	o := orm.NewOrm()
	m := models.WxMessage{}
	count, err := o.QueryTable(m.TableName()).Filter(m.FN_MessageType(), MessageType).Filter(searchFiled + "__icontains", search).Count()
	return count, err
}

func HTWxMessageGetList(wxmessages *[]models.WxMessage, fields []string , MessageType int, offset int64, limit int, search string, searchFiled string, orderby string) error {
	o := orm.NewOrm()
	m := models.WxMessage{}
	_, err := o.QueryTable(m.TableName()).Filter(m.FN_MessageType(), MessageType).Filter(searchFiled + "__icontains", search).OrderBy(orderby).Offset(offset).Limit(limit).All(wxmessages, fields...)
	return err
}

func HTWxMessageDelete(Ids []int64) (int64, error) {
	o := orm.NewOrm()
	m := models.WxMessage{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Delete()
	return count, err
}
func HTWxMessageUpdate(wxmessage *models.WxMessage) error {
	o := orm.NewOrm()
	_, err := o.Update(wxmessage)
	return err
}